package com.heng.atomics;

import java.util.concurrent.atomic.LongAccumulator;
import java.util.concurrent.atomic.LongAdder;
import java.util.function.LongBinaryOperator;

public class XXXLongAdderApiDemo7 {
    public static void main(String[] args) {
        LongAdder longAdder = new LongAdder();

        longAdder.increment();
        longAdder.increment();
        longAdder.increment();

        System.out.println(longAdder.sum());
        System.out.println("==================");

        LongAccumulator longAccumulator = new LongAccumulator((x,y)->x + y,0);

        //ccc
        longAccumulator.accumulate(1);
        longAccumulator.accumulate(3);
        System.out.println(longAccumulator.get());

        System.out.println("-----------");
        LongAccumulator longAccumulator2 = new LongAccumulator(new LongBinaryOperator() {
            @Override
            public long applyAsLong(long left, long right) {
                return left+right;
            }
        },0);

        //ccc
        longAccumulator2.accumulate(1);
        longAccumulator2.accumulate(3);
        System.out.println(longAccumulator2.get());

    }
}
